package cn.online.service;

import java.util.List;

import cn.online.dao.CourseDao;
import cn.online.dao.ProblemDao;
import cn.online.model.Course;
import cn.online.model.Problem;

public class CourseService {
	
	private CourseDao courseDao;
	private ProblemDao problemDao;
	
	public void setCourseDao(CourseDao courseDao) {
		this.courseDao = courseDao;
	}
	public void setProblemDao(ProblemDao problemDao) {
		this.problemDao = problemDao;
	}
	
	public void insert(Course course){
		courseDao.save(course);
	}
	
	public void delete(Integer id){
		List<Problem> problemL = problemDao.getProblemByCourseId(id);
		Course course = courseDao.findById(id);
		if(course!=null){
			for(Problem p:problemL){
				problemDao.delete(p);
			}
		}
		courseDao.delete(course);
	}
	
	public void update(Course course){
		courseDao.update(course);
	}
	
	public List<Course> findAll(){
		return courseDao.findAll();
	}
	
	public Course findById(Integer id){
		return courseDao.findById(id);
	}
}
